package com.estar.assistsurvy.adapter;

import com.estar.assistsurvy.R;
import com.estar.assistsurvy.entity.OptionList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SubjectListviewAdapter extends BaseAdapter {

	private OptionList[] optionList;
	private int[] icons;
	private LayoutInflater inflater;
	private int selectItem=-1;
	
	public SubjectListviewAdapter(OptionList[] optionList, Context context) {
		super();
		this.optionList = optionList;
		inflater=LayoutInflater.from(context);
		icons=new int[]{R.drawable.icon_a,R.drawable.icon_b,R.drawable.icon_c,R.drawable.icon_d};
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return optionList.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return optionList[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(convertView==null){
			convertView=inflater.inflate(R.layout.listview_examoption, null);
			holder=new ViewHolder();
			holder.option_icon=(ImageView) convertView.findViewById(R.id.option_icon);
			holder.option_item=(TextView) convertView.findViewById(R.id.option_item);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		
		holder.option_item.setText(optionList[position].getContent());
		if(selectItem==position){
			holder.option_icon.setImageResource(R.drawable.icon_select);
		}else{
			holder.option_icon.setImageResource(icons[position]);
		}
		
		return convertView;
	}
	
	public void setSelectItem(int selectItem){
		this.selectItem=selectItem;
	}
	
	private class ViewHolder{
		private ImageView option_icon;
		private TextView option_item;
	}

}
